#!/usr/bin/php
<?php
require_once dirname(__FILE__) . '/simple_helpers.inc';


/*
 * This file performs some basic tests for languages with regular expression literal types.
 */ 


$simple = array('/someregex/' => '',
                '/some\\/regex/' => '',
                '/some\\\\/regex' => 'regex',
                // the following should not match.
                'x/y/z' => 'x/y/z',
                'x / y / z' => 'x / y / z',
                'return (x / y / z)' => 'return (x / y / z)',                
                // ...
                '/^(\[) *@?([\w-]+) *([!*$^~=]*) *(\'?"?)(.*?)\4 *\]/,/^(:)([\w-]+)\("?\'?(.*?(\(.*?\))?[^(]*?)"?\'?\)/' => ',',
                '/\\\\\\\\thisisescaped\/i;     stillgoing/iEND' => 'END'
                
);

                
// Ruby's regexes may use dynamic delimiters if they are prefixed with
// %r
$ruby = array('%r!this is a regex!' => '',
              '%r!this is a regex!mxu' => '',  
              '%r!this is a regex!mxie' => '',  
              '%r[ ... ]' => '',
              '%r[ ...\\[3\\] ]o' => '',
              '%r{ .\\}.. }x' => '',
              '%r{ .\\}.. }x' => '',
              '%r{ .\\}.. }xy' => 'y',
              '%r|/|' => ''
);

$perl = array(
              '$string =~ m/sought_text/;' => '$string =~ ;',
              'if($string =~ m/(B|b)ill (C|c)linton/)' => 'if($string =~ )',
              '/[^AEIOUYaeiouy]/' => '',
              '$string =~ tr/[A,E,I,O,U,Y]/[1,2,3,4,5]/;' => '$string =~ ;',
              's/x/y/' => ''
);




$languages = array(
  'js' => $simple,
  'rb' => array_merge($simple, $ruby),
  'perl' => array_merge($perl, $simple),
);




foreach($languages as $lang=>$tests)
{
  $g = $luminous_grammars->GetGrammar($lang);
  foreach($tests as $t=>$out)
  {
    test($lang, $t, $out, '%(<REGEX>.*?</REGEX>)|(<.*?>)%', '');
  }
}

exit($EXIT_STATUS);
